package c1703;

import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;

public class I {
    public static void main(String[] args) {
        int n = cin.nextInt();
        PriorityQueue<Long> Q = new PriorityQueue<>();
        long tot = 0;
        while (n-- > 0) {
            Q.offer(cin.nextLong());
        }
        while (Q.size() > 1) {
            long x = Q.peek();
            Q.poll();
            long y = Q.peek();
            Q.poll();
            tot += x + y;
            Q.offer(x + y);
        }
        cout.println(tot);
        cout.close();
    }
 
    static QuickInput cin = new QuickInput();//大量输入优化版本
    static PrintWriter cout = new PrintWriter(new BufferedOutputStream(System.out));//大量输出优化版本
    static PrintWriter cerr = new PrintWriter(System.err, true);//开启调试模式,一般输出量不大，不需要buffered


    static class QuickInput {
        BufferedReader buf;
        StringTokenizer tok;

        QuickInput() {
            buf = new BufferedReader(new InputStreamReader(System.in));
        }

        boolean hasNext() {
            while (tok == null || !tok.hasMoreElements()) {
                try {
                    tok = new StringTokenizer(buf.readLine());
                } catch (Exception e) {
                    return false;
                }
            }
            return true;
        }

        String next() {
            if (hasNext()) return tok.nextToken();
            return null;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }

        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}